<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="所属电影场次id" prop="scheduleId">
      <el-input v-model="dataForm.scheduleId" placeholder="所属电影场次id"></el-input>
    </el-form-item>
    <el-form-item label="选购座位id" prop="seatIds">
      <el-input v-model="dataForm.seatIds" placeholder="选购座位id"></el-input>
    </el-form-item>
    <el-form-item label="订单号" prop="orderNo">
      <el-input v-model="dataForm.orderNo" placeholder="订单号"></el-input>
    </el-form-item>
    <el-form-item label="订单状态 1.待支付 2.支付成功 3.申请退单 4.退单成功 5.退单失败 6.订单取消" prop="status">
      <el-input v-model="dataForm.status" placeholder="订单状态 1.待支付 2.支付成功 3.申请退单 4.退单成功 5.退单失败 6.订单取消"></el-input>
    </el-form-item>
    <el-form-item label="所属用户id" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="所属用户id"></el-input>
    </el-form-item>
    <el-form-item label="影院名称" prop="cinemaId">
      <el-input v-model="dataForm.cinemaId" placeholder="影院名称"></el-input>
    </el-form-item>
    <el-form-item label="放映厅名称" prop="hallName">
      <el-input v-model="dataForm.hallId" placeholder="放映厅名称"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          createTime: '',
          payTime: '',
          refundTime: '',
          refundSuccessTime: '',
          refundCause: '',
          scheduleId: '',
          seatIds: '',
          seat: '',
          price: '',
          deleted: '',
          orderNo: '',
          status: '',
          userId: '',
          cinemaId: '',
          cinemaName: '',
          hallName: '',
          scheduleTime: '',
          movieId: '',
          code: '',
          buyCount: '',
          totalPrice: ''
        },
        dataRule: {
          createTime: [
            { required: true, message: '订单时间不能为空', trigger: 'blur' }
          ],
          payTime: [
            { required: true, message: '订单支付时间不能为空', trigger: 'blur' }
          ],
          refundTime: [
            { required: true, message: '订单退单时间不能为空', trigger: 'blur' }
          ],
          refundSuccessTime: [
            { required: true, message: '退单成功时间不能为空', trigger: 'blur' }
          ],
          refundCause: [
            { required: true, message: '拒绝退款原因不能为空', trigger: 'blur' }
          ],
          scheduleId: [
            { required: true, message: '所属电影场次id不能为空', trigger: 'blur' }
          ],
          seatIds: [
            { required: true, message: '选购座位id不能为空', trigger: 'blur' }
          ],
          seat: [
            { required: true, message: '选购座位信息不能为空', trigger: 'blur' }
          ],
          price: [
            { required: true, message: '选购座位信息不能为空', trigger: 'blur' }
          ],
          deleted: [
            { required: true, message: '     * 订单状态 1.待支付 2.支付成功 3.申请退单 4.退单成功 5.退单失败 6.订单取消不能为空', trigger: 'blur' }
          ],
          orderNo: [
            { required: true, message: '订单号不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '     * 订单状态 1.待支付 2.支付成功 3.申请退单 4.退单成功 5.退单失败 6.订单取消不能为空', trigger: 'blur' }
          ],
          userId: [
            { required: true, message: '所属用户id不能为空', trigger: 'blur' }
          ],
          cinemaId: [
            { required: true, message: '影院名称不能为空', trigger: 'blur' }
          ],
          cinemaName: [
            { required: true, message: '影院名称不能为空', trigger: 'blur' }
          ],
          hallName: [
            { required: true, message: '放映厅名称不能为空', trigger: 'blur' }
          ],
          scheduleTime: [
            { required: true, message: '上映时间不能为空', trigger: 'blur' }
          ],
          movieId: [
            { required: true, message: '电影id不能为空', trigger: 'blur' }
          ],
          code: [
            { required: true, message: '验证码不能为空', trigger: 'blur' }
          ],
          buyCount: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          totalPrice: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      changeStatus(row){
this.$http({
            url: this.$http.adornUrl(
              `/sys/user/update`
            ),
            method: "post",
            data: this.$http.adornData({
              id: row.id,
              status: row.status,
            }),
          }).then(({ data }) => {
            if (data && data.code === 0) {
              console.log(data)
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
              });
            } else {
              this.$message.error(data.msg);
            }
          });  
          
          },
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/cb/order/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.createTime = data.order.createTime
                this.dataForm.payTime = data.order.payTime
                this.dataForm.refundTime = data.order.refundTime
                this.dataForm.refundSuccessTime = data.order.refundSuccessTime
                this.dataForm.refundCause = data.order.refundCause
                this.dataForm.scheduleId = data.order.scheduleId
                this.dataForm.seatIds = data.order.seatIds
                this.dataForm.seat = data.order.seat
                this.dataForm.price = data.order.price
                this.dataForm.deleted = data.order.deleted
                this.dataForm.orderNo = data.order.orderNo
                this.dataForm.status = data.order.status
                this.dataForm.userId = data.order.userId
                this.dataForm.cinemaId = data.order.cinemaId
                this.dataForm.cinemaName = data.order.cinemaName
                this.dataForm.hallName = data.order.hallName
                this.dataForm.scheduleTime = data.order.scheduleTime
                this.dataForm.movieId = data.order.movieId
                this.dataForm.code = data.order.code
                this.dataForm.buyCount = data.order.buyCount
                this.dataForm.totalPrice = data.order.totalPrice
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/cb/order/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'createTime': this.dataForm.createTime,
                'payTime': this.dataForm.payTime,
                'refundTime': this.dataForm.refundTime,
                'refundSuccessTime': this.dataForm.refundSuccessTime,
                'refundCause': this.dataForm.refundCause,
                'scheduleId': this.dataForm.scheduleId,
                'seatIds': this.dataForm.seatIds,
                'seat': this.dataForm.seat,
                'price': this.dataForm.price,
                'deleted': this.dataForm.deleted,
                'orderNo': this.dataForm.orderNo,
                'status': this.dataForm.status,
                'userId': this.dataForm.userId,
                'cinemaId': this.dataForm.cinemaId,
                'cinemaName': this.dataForm.cinemaName,
                'hallName': this.dataForm.hallName,
                'scheduleTime': this.dataForm.scheduleTime,
                'movieId': this.dataForm.movieId,
                'code': this.dataForm.code,
                'buyCount': this.dataForm.buyCount,
                'totalPrice': this.dataForm.totalPrice
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
